package wifiunion.com.notice.presenter;

import android.content.Context;
import android.os.Handler;
import android.util.Log;

import java.io.File;
import java.util.HashMap;

import wifiunion.com.notice.BaseView;
import wifiunion.com.notice.Constants;
import wifiunion.com.notice.HttpUtils;
import wifiunion.com.notice.UploadFileContact;

/**
 * Created by Administrator on 2018/4/10.
 */

public class UploadFilePresenter implements UploadFileContact.Presenter, UploadFileContact.Callback {

    private BaseView mView;
    private Context mContext;


    /**
     * 0 上传文件
     */
    private int type;

    private Handler handler;
    public UploadFilePresenter(Context context, BaseView view, int type, Handler handler) {
        mView = view;
        mContext = context;
        this.type = type;
        this.handler = handler;
    }


    @Override
    public void onSuccess(final Object data) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                switch (type) {
                    case 0:
                        ((UploadFileContact.uploadFileView) mView).onUploadFileSuccess((String) data);
                        break;
                }
            }
        });
    }

    @Override
    public void onServerFailed(final Object errorObj) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                switch (type) {

                    case 0:

                        Log.i("test","########写文件失败");
                        ((UploadFileContact.uploadFileView) mView).onUploadFileFailed((String) errorObj);
                        break;


                }
            }
        });

    }


    /**
     * 上传文件
     *
     * @param f
     */
    public void uploadFile(File file) {
        HttpUtils.HttpUploadPackage_Asyn(Constants.HTTP_URL_HEADER + Constants.HTTP_URL_UPLOAD, file, this);
    }







    @Override
    public void onNetFailed() {
        ((UploadFileContact.uploadFileView) mView).onUploadFileFailed("上传文件异常");
    }

    @Override
    public void start() {

    }

    @Override
    public void start(HashMap<String, Object> param1s) {

    }

}
